function submitForm(formName, formAction) {
	clearErrorMessages();
    var form = document.forms[formName];
    form.action = formAction;
    form.submit();
}

String.prototype.trim = function() {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}
String.prototype.ltrim = function() {
    return this.replace(/^\s*/, "");
}
String.prototype.rtrim = function() {
    return this.replace(/\s*$/, "");
}

function trim(objStr) {
    return objStr.replace(/(^\s*)|(\s*$)/g, "");
}

function isEmpty(s)
{
    return ((s == null) || (s.length == 0));
}

function atLeastOneRecordChecked(currentDivName) {
    var o;
    var resultList;
    if (isEmpty(currentDivName)) {
        resultList = document.getElementsByTagName("input");
    } else {
        o = document.getElementById(currentDivName);
        resultList = o.getElementsByTagName("input");
    }
    for (var i = 0; i < resultList.length; i++) {
        if (resultList[i].type == 'checkbox') {
            if (resultList[i].checked) {
                return true;
            }
        }
    }
    return false;
}

function onlyOneRecordChecked(currentDivName) {
    var o;
    var resultList;
    var hasChecked = false;
    if (isEmpty(currentDivName)) {
        resultList = document.getElementsByTagName("input");
    } else {
        o = document.getElementById(currentDivName);
        resultList = o.getElementsByTagName("input");
    }
    for (var i = 0; i < resultList.length; i++) {
        if (resultList[i].type == 'checkbox') {
            if (resultList[i].checked) {
                if (!hasChecked) {
                    hasChecked = true;
                } else {
                    return false;
                }
            }
        }
    }
    return hasChecked;
}

function clearErrorMessages() {
    while (document.getElementById("errorMessages")) {
        document.getElementById("errorMessages").parentNode.removeChild(document.getElementById("errorMessages"));
    }
}

function isToPagelessThanTotalPage(toPage, totalPage) {
    if (trim(toPage) == "") {
        return false;
    }
    if (isNaN(toPage)) {
        return false;
    }
    toPage = parseInt(toPage);
    totalPage = parseInt(totalPage);
    if (toPage > totalPage) {
        return false;
    }
    return true;
}

function openNewWindow(url, height, width, toolbar, scrollbars, location, statusbar, menubar, resizable, winname) {
	var day = new Date();
	var id = day.getTime();

    if (winname != null && winname != '') {
        id = winname;
    }

    var topMargin=(screen.height-height)/2;
    if(topMargin<0)topMargin=0;
    var leftMargin=(screen.width-width)/2;
    if(leftMargin<0)leftMargin=0;
    var param = getWinParamValue("height", height, 400, "false") +
		getWinParamValue("width", width, 400, "false") +
        getWinParamValue("top", topMargin, topMargin, "false") +
		getWinParamValue("left", leftMargin,leftMargin, "false") +
        getWinParamValue("toolbar", toolbar, 0, "false") +
		getWinParamValue("scrollbars", scrollbars, 1, "false") +
		getWinParamValue("location", location, 0, "false") +
		getWinParamValue("status", statusbar, 0, "false") +
		getWinParamValue("menubar", menubar, 0, "false") +
		getWinParamValue("resizable", resizable, 1, "true");

	var newWin = window.open(url, id, param);
    return newWin;
}

function getWinParamValue(paramName, paramValue, defaultValue, lastOne) {
	var returnValue = paramName + "=";
	if (paramValue == null) {
		returnValue = returnValue + defaultValue;
	 } else {
	 	returnValue = returnValue + paramValue;
	 }
	 if (lastOne != 'true') {
	 	returnValue = returnValue + ",";
	 }
	 return returnValue;
}